Grid grid = null;

void setup(){
  size( 600, 600); 
  grid = new Grid( 10, 10);
}

void draw(){
  grid.draw();
  
};

void keyPressed() {
  grid.keyHandler();
}

int sx = 40;
int sy = 40;

interface HandleInput{
  
  boolean clickHandler();
  boolean keyHandler();
};

class Grid implements HandleInput{
  
  int maxX;
  int maxY;
  
  int hilightX;
  int hilightY;
  
  Grid( int sizeX, int sizeY){
    maxX = sizeX;
    maxY = sizeY;
    hilightX = 0;
    hilightY = 0;
  };
  
  void draw(){
    for( int x=0; x < maxX; x++){
      for( int y=0; y < maxY; y++){
        fill( 128);
        if( hilightX == x && hilightY == y){
          stroke( 255);
        }else{
          stroke( 100);
        };
        rect( x * sx, y * sy, sx - 1, sy - 1);
      };
    };
  };
  
  boolean clickHandler(){
     return false;
  };
  boolean keyHandler(){
    if( key == CODED){
      switch( keyCode){
        case UP:
          if( hilightY > 0){
            hilightY--;
          };
          break;
        case DOWN:
          if( hilightY < maxY -1){
            hilightY++;
          };
          break;
        case LEFT:
          if( hilightX > 0){
            hilightX--;
          };
          break;
        case RIGHT:
          if( hilightX < maxX -1){
            hilightX++;
          };
          break;
      };
    };
    return false;
  };
  
  
};
